import { getDetailsByPhone } from '@/api/admin/user'
import store from "@/store";


var validatePhone = (rule, value, callback) => {
  getDetailsByPhone(value).then(response => {
    if (window.boxType === 'edit') callback()
    const result = response.data.data
    if (result !== null) {
      callback(new Error('当前手机号已经存在'))
    } else {
      callback()
    }
  })
}
export const tableOption = {
  dialogType: 'drawer',
  dialogClickModal: false,
  dialogMenuPosition: 'center',
  border: true,
  index: true,
  indexLabel: '序号',
  stripe: true,
  searchMenuSpan: 6,
  menuWidth: 180,
  menuAlign: 'center',
  menuType: 'menu',
  editBtn: false,
  delBtn: false,
  addBtn: false,
  copyBtn: false,
  viewBtn: true,
  align: 'center',
  column: [{
    label: 'id',
    prop: 'accountId',
    dataType: 'number',
    display: false,
    showColumn: false,
    hide: true
  }, {
    label: '头像',
    prop: 'avatar',
    type: 'upload',
    accept: 'image/png,image/jpeg,image/jpg',
    listType: 'picture-img',
    loadText: '头像上传中、请稍等',
    tip: '请选择头像上传',
    propsHttp: {
      res: 'data'
    },
    action: store.getters.avatarAction,
    width: 100,
    span: 24
  },
  {
    label: '用户名',
    prop: 'username',
    addDisplay: false,
    editDisplay: false,
    span: 24
  }, {
    label: '姓名',
    prop: 'nickname',
    search: true,
    span: 24,
    rules: [{
      required: true,
      message: '请输入姓名'
    }]
  }, {
    label: '手机号',
    prop: 'phone',
    span: 24,
    editDisplay: false,
    search: true,
    rules: [{
      required: true,
      message: '请输入手机号'
    }, {
      min: 11,
      max: 11,
      message: '长度在 11 个字符',
      trigger: 'blur'
    },
    { validator: validatePhone, trigger: 'blur' }]
  }, {
    label: '邮箱',
    prop: 'email',
    search: true,
    span: 24,
    addDisplay: false,
    editDisplay: false
  }, {
    label: '角色',
    prop: 'roles',
    type: 'select',
    dataType: 'array',
    formslot: true,
    slot: true,
    overHidden: true,
    span: 24,
    rules: [{
      required: true,
      message: '请选择角色',
      trigger: 'blur'
    }]
  }, {
    label: '所属部门',
    prop: 'deptId',
    formslot: true,
    slot: true,
    span: 24,
    type: 'select',
    dataType: "number"
  }, {
    width: 160,
    label: '创建时间',
    prop: 'createTime',
    type: 'datetime',
    format: 'yyyy-MM-dd HH:mm',
    valueFormat: 'timestamp',
    editDisplay: false,
    addDisplay: false,
  }, {
    width: 160,
    label: '更新时间',
    prop: 'updateTime',
    type: 'datetime',
    format: 'yyyy-MM-dd HH:mm',
    valueFormat: 'timestamp',
    editDisplay: false,
    addDisplay: false,
    hide: true
  },
  ]
}
